
import React from 'react'
import {Form,Modal,Input,Message} from 'antd'
import store from "./store";
import {AddZone} from "../../../../api/work/system/RuleApi";

class AddZoneForm extends React.Component{
    constructor(props) {
        super(props);
        this.state = {
            loading:false
        }
    }

    handleSubmit = () => {
        this.props.form.validateFields((error,formData) => {
            if (!error) {
                formData["id"] = store.id;
                formData["type"] = 1;
                formData["sub_type"] = 0;
                AddZone(formData).then(response => {
                    if (response.data.code === 200){
                        store.fetchRecords();
                        Message.success(response.data.msg)
                        store.addZoneVisible = false;
                    }
                })
            }
        })
    };

    render() {
        const {getFieldDecorator} = this.props.form;
        return (
            <Modal
                visible
                width={800}
                maskClosable={false}
                title={"添加页面"}
                onCancel={() => store.addZoneVisible = false}
                confirmLoading={this.state.loading}
                onOk={this.handleSubmit}>
                <Form labelCol={{span: 6}} wrapperCol={{span: 14}}>
                    <Form.Item  label="操作">
                        {getFieldDecorator('key', {initialValue: "",rules: [{required:true,message:"操作路由不能为空"}]})(
                            <Input placeholder="请输入操作路由" required />
                        )}
                    </Form.Item>
                    <Form.Item label="标题">
                        {getFieldDecorator('label', {initialValue: "",rules: [{required:true,message:"标题不能为空"}]})(
                            <Input placeholder="请输入标题"/>
                        )}
                    </Form.Item>
                </Form>
            </Modal>
        )
    }
}

export default Form.create()(AddZoneForm);
